<?php

Route::redirect('/', '/products')->name('root');
// 首页，商品列表
Route::get('products', 'ProductsController@index')->name('products.index');

Auth::routes(['verify' => true]);

// auth 中间件代表需要登录， verified 中间件代表需要经过邮箱验证
Route::group(
    ['middleware' => ['auth', 'verified']],
    function () {
        // 我的收货地址
        Route::get('user_addresses', 'UserAddressesController@index')->name('user_addresses.index');
        // 新增收货地址
        Route::get('user_addresses/create', 'UseraddressesController@create')->name('user_addresses.create');
        // 插入收货地址
        Route::post('user_addresses', 'UserAddressesController@store')->name('user_addresses.store');
        // 编辑收货地址
        Route::get('user_addresses/{user_address}', 'UserAddressesController@edit')->name('user_addresses.edit');
        // 更新收货地址
        Route::put('user_addresses/{user_address}', 'UserAddressesController@update')->name('user_addresses.update');
        // 删除收货地址
        Route::delete('user_addresses/{user_address}', 'UserAddressesController@destroy')->name(
            'user_addresses.destroy'
        );
        // 新增收藏
        Route::post('products/{product}/favorite', 'ProductsController@favor')->name('products.favor');
        // 取消收藏
        Route::delete('products/{product}/favorite', 'ProductsController@disfavor')->name('products.disfavor');
        // 我的商品收藏
        Route::get('products/favorites', 'ProductsController@favorites')->name('products.favorites');
        // 加入购物车
        Route::post('cart', 'CartController@add')->name('cart.add');
        // 购物车
        Route::get('cart', 'CartController@index')->name('cart.index');
        // 删除购物车种商品
        Route::delete('cart/{sku}', 'CartController@remove')->name('cart.remove');
        // 创建订单
        Route::post('orders', 'OrdersController@store')->name('orders.store');
        // 订单列表
        Route::get('orders', 'OrdersController@index')->name('orders.index');
        // 订单详情
        Route::get('orders/{order}', 'OrdersController@show')->name('orders.show');
        // 确认收货
        Route::post('orders/{order}/received', 'OrdersController@received')->name('orders.received');
        // 支付宝支付
        Route::get('payment/{order}/alipay', 'PaymentController@payByAlipay')->name('payment.alipay');
        // 支付宝前端同步跳转
        Route::get('payment/alipay/return', 'PaymentController@alipayReturn')->name('payment.alipay.return');
        // 微信支付二维码
        Route::get('payment/{order}/wecht', 'PaymentController@payByWechat')->name('payment.wechat');
        // 订单评价
        Route::get('orders/{order}/review', 'OrdersController@review')->name('orders.review.show');
        // 创建订单评价
        Route::post('orders/{order}/review', 'OrdersController@sendReview')->name('orders.review.store');
        // 订单退款
        Route::post('orders/{order}/apply_refund', 'OrdersController@applyRefund')->name('orders.apply_refund');
        // 检测优惠券
        Route::get('coupon_codes/{code}', 'CouponCodesController@show')->name('coupon_codes.show');
        // 众筹商品下单
        Route::post('crowdfunding_orders', 'OrdersController@crowdfunding')->name('crowdfunding_orders.store');
    }
);
// 支付宝异步回调
Route::post('payment/alipay/notify', 'PaymentController@alipayNotify')->name('payment.alipay.notify');
// 微信支付异步回调
Route::post('payment/wechat/notify', 'PaymentController@wechatNotify')->name('payment.wechat.notify');
// 微信支付退款异步通知
Route::post('payment/wechat/refund_notify', 'PaymentController@wechatRefundNotify')->name(
    'payment.wechat.refund_notify'
);
// 商品详情
Route::get('products/{product}', 'ProductsController@show')->name('products.show');
